        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>FrictionJoint class / box2d Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d" data-type="FrictionJoint">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d.html">box2d</a> &rsaquo; <a href="../box2d/FrictionJoint.html">FrictionJoint</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>FrictionJoint</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<pre class="source">
class FrictionJoint extends Joint {
 final vec2 _localAnchorA;
 final vec2 _localAnchorB;

 vec2 _linearImpulse;
 num _angularImpulse;
 num _maxForce;
 num _maxTorque;

 FrictionJoint(FrictionJointDef def)
     : super(def),
       _localAnchorA = new vec2.copy(def.localAnchorA),
       _localAnchorB = new vec2.copy(def.localAnchorB),
       _linearImpulse = new vec2.zero(),
       _angularImpulse = 0.0,
       _maxForce = def.maxForce,
       _maxTorque = def.maxTorque { }

 void getLocalAnchorA(vec2 argOut) {
   bodyA.getWorldPointToOut(_localAnchorA, argOut);
 }

 void getLocalAnchorB(vec2 argOut) {
   bodyB.getWorldPointToOut(_localAnchorB, argOut);
 }

 void getReactionForce(num inv_dt, vec2 argOut) {
   argOut.copyFrom(_linearImpulse).scale(inv_dt);
 }

 num getReactionTorque(num inv_dt) =&gt; inv_dt * _angularImpulse;

 void set maxForce(num force) {
   assert(force &gt;= 0.0);
   _maxForce = force;
 }

 num get maxForce =&gt; _maxForce;

 void set maxTorque(num torque) {
   assert(torque &gt;= 0.0);
   _maxTorque = torque;
 }

 num get maxTorque =&gt; _maxTorque;

 void initVelocityConstraints(TimeStep time_step) {
   // Compute the effective mass matrix.
   vec2 r1 = _localAnchorA - bodyA.localCenter;
   vec2 r2 = _localAnchorB - bodyB.localCenter;

   bodyA.originTransform.rotation.transform(r1);
   bodyB.originTransform.rotation.transform(r2);

   // J = [-I -r1_skew I r2_skew]
   // [ 0 -1 0 1]
   // r_skew = [-ry; rx]

   // Matlab
   // K = [ mA+r1y^2*iA+mB+r2y^2*iB, -r1y*iA*r1x-r2y*iB*r2x, -r1y*iA-r2y*iB]
   // [ -r1y*iA*r1x-r2y*iB*r2x, mA+r1x^2*iA+mB+r2x^2*iB, r1x*iA+r2x*iB]
   // [ -r1y*iA-r2y*iB, r1x*iA+r2x*iB, iA+iB]

   mat2 K = new mat2.zero();
   K.col0.x = bodyA.invMass + bodyB.invMass +
              bodyA.invInertia * r1.y * r1.y + bodyB.invInertia * r2.y * r2.y;
   K.col0.y = -bodyA.invInertia * r1.x * r1.y - bodyB.invInertia * r2.x * r2.y;
   K.col1.x = K.col0.y;
   K.col1.y = bodyA.invMass + bodyB.invMass +
              bodyA.invInertia * r1.x * r1.x + bodyB.invInertia * r2.x * r2.x;

   mat2 linearMass = new mat2.copy(K);
   linearMass.invert();

   num angularMass = bodyA.invInertia + bodyB.invInertia;
   if (angularMass &gt; 0.0) {
     angularMass = 1.0 / angularMass;
   }

   if (time_step.warmStarting) {
     // Scale impulses.
     _linearImpulse.scale(time_step.dtRatio);
     _angularImpulse *= time_step.dtRatio;

     vec2 P = new vec2.copy(_linearImpulse);

     bodyA.linearVelocity.x -= bodyA.invMass * P.x;
     bodyA.linearVelocity.y -= bodyA.invMass * P.y;
     bodyA.angularVelocity -= bodyA.invInertia * (cross(r1, P) + _angularImpulse);

     bodyB.linearVelocity.x += bodyB.invMass * P.x;
     bodyB.linearVelocity.y += bodyB.invMass * P.y;
     bodyB.angularVelocity += bodyB.invInertia * (cross(r2, P) + _angularImpulse);
   } else {
     _linearImpulse.splat(0.0);
     _angularImpulse = 0.0;
   }
 }

 void solveVelocityConstraints(TimeStep time_step) {
   // Solve angular friction
   {
     final num Cdot = bodyB.angularVelocity - bodyA.angularVelocity;
     num angularMass = bodyA.invInertia + bodyB.invInertia;
     if (angularMass &gt; 0.0) {
       angularMass = 1.0 / angularMass;
     }
     num impulse = -angularMass * Cdot;

     final num oldImpulse = _angularImpulse;
     final num maxImpulse = time_step.dt * _maxTorque;
     _angularImpulse = clamp(_angularImpulse + impulse, -maxImpulse, maxImpulse);
     impulse = _angularImpulse - oldImpulse;

     bodyA.angularVelocity -= bodyA.invInertia * impulse;
     bodyB.angularVelocity += bodyB.invInertia * impulse;
   }

   // Solve linear friction
   {
     final vec2 r1 = _localAnchorA - bodyA.localCenter;
     final vec2 r2 = _localAnchorB - bodyB.localCenter;

     bodyA.originTransform.rotation.transform(r1);
     bodyB.originTransform.rotation.transform(r2);

     vec2 temp = cross(bodyA.angularVelocity, r1);
     vec2 Cdot = cross(bodyB.angularVelocity, r2);

     Cdot.add(bodyB.linearVelocity).sub(bodyA.linearVelocity).sub(temp);

     mat2 K = new mat2.zero();
     K.col0.x = bodyA.invMass + bodyB.invMass +
                bodyA.invInertia * r1.y * r1.y + bodyB.invInertia * r2.y * r2.y;
     K.col0.y = -bodyA.invInertia * r1.x * r1.y - bodyB.invInertia * r2.x * r2.y;
     K.col1.x = K.col0.y;
     K.col1.y = bodyA.invMass + bodyB.invMass +
                bodyA.invInertia * r1.x * r1.x + bodyB.invInertia * r2.x * r2.x;

     mat2 linearMass = new mat2.copy(K);
     linearMass.invert();

     vec2 impulse = new vec2.copy(Cdot);
     linearMass.transform(impulse);
     impulse.negate();

     vec2 oldImpulse = new vec2.copy(_linearImpulse);
     _linearImpulse.add(impulse);

     num maxImpulse = time_step.dt * _maxForce;
     if (_linearImpulse.length2 &gt; maxImpulse * maxImpulse) {
       _linearImpulse.normalize();
       _linearImpulse.scale(maxImpulse);
     }

     impulse.copyFrom(_linearImpulse).sub(oldImpulse);

     bodyA.linearVelocity.x -= impulse.x * bodyA.invMass;
     bodyA.linearVelocity.y -= impulse.y * bodyA.invMass;
     bodyA.angularVelocity -= bodyA.invInertia * cross(r1, impulse);

     bodyB.linearVelocity.x += impulse.x * bodyB.invMass;
     bodyB.linearVelocity.y += impulse.y * bodyB.invMass;
     bodyB.angularVelocity += bodyB.invInertia * cross(r2, impulse);
   }
 }

 bool solvePositionConstraints(num baumgarte) =&gt; true;
}
</pre>
</div>
<h3>Extends</h3>
<p>
<span class="type-box"><span class="icon-class"></span><a href="../box2d/Joint.html">Joint</a></span>&nbsp;&gt;&nbsp;<span class="type-box"><span class="icon-class"></span><strong>FrictionJoint</strong></span></p>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="FrictionJoint">
<button class="show-code">Code</button>
new <strong>FrictionJoint</strong>(<a href="../box2d/FrictionJointDef.html">FrictionJointDef</a> def) <a class="anchor-link" href="#FrictionJoint"
              title="Permalink to FrictionJoint.FrictionJoint">#</a></h4>
<div class="doc">
<pre class="source">
FrictionJoint(FrictionJointDef def)
   : super(def),
     _localAnchorA = new vec2.copy(def.localAnchorA),
     _localAnchorB = new vec2.copy(def.localAnchorB),
     _linearImpulse = new vec2.zero(),
     _angularImpulse = 0.0,
     _maxForce = def.maxForce,
     _maxTorque = def.maxTorque { }
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field inherited"><h4 id="active">
<button class="show-code">Code</button>
final bool         <strong>active</strong> <a class="anchor-link"
            href="#active"
            title="Permalink to FrictionJoint.active">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<p>Short-cut function to determine if either body is inactive. </p>
<pre class="source">
bool get active =&gt; bodyA.active &amp;&amp; bodyB.active;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="bodyA">
<button class="show-code">Code</button>
<a href="../box2d/Body.html">Body</a>         <strong>bodyA</strong> <a class="anchor-link"
            href="#bodyA"
            title="Permalink to FrictionJoint.bodyA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
bodyA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="bodyB">
<button class="show-code">Code</button>
<a href="../box2d/Body.html">Body</a>         <strong>bodyB</strong> <a class="anchor-link"
            href="#bodyB"
            title="Permalink to FrictionJoint.bodyB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
bodyB
</pre>
</div>
</div>
<div class="field inherited"><h4 id="collideConnected">
<button class="show-code">Code</button>
bool         <strong>collideConnected</strong> <a class="anchor-link"
            href="#collideConnected"
            title="Permalink to FrictionJoint.collideConnected">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
collideConnected
</pre>
</div>
</div>
<div class="field inherited"><h4 id="edgeA">
<button class="show-code">Code</button>
<a href="../box2d/JointEdge.html">JointEdge</a>         <strong>edgeA</strong> <a class="anchor-link"
            href="#edgeA"
            title="Permalink to FrictionJoint.edgeA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
edgeA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="edgeB">
<button class="show-code">Code</button>
<a href="../box2d/JointEdge.html">JointEdge</a>         <strong>edgeB</strong> <a class="anchor-link"
            href="#edgeB"
            title="Permalink to FrictionJoint.edgeB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
edgeB
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invIA">
<button class="show-code">Code</button>
num         <strong>invIA</strong> <a class="anchor-link"
            href="#invIA"
            title="Permalink to FrictionJoint.invIA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
invIA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invIB">
<button class="show-code">Code</button>
num         <strong>invIB</strong> <a class="anchor-link"
            href="#invIB"
            title="Permalink to FrictionJoint.invIB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
invIB
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invMassA">
<button class="show-code">Code</button>
num         <strong>invMassA</strong> <a class="anchor-link"
            href="#invMassA"
            title="Permalink to FrictionJoint.invMassA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
invMassA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invMassB">
<button class="show-code">Code</button>
num         <strong>invMassB</strong> <a class="anchor-link"
            href="#invMassB"
            title="Permalink to FrictionJoint.invMassB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
invMassB
</pre>
</div>
</div>
<div class="field inherited"><h4 id="islandFlag">
<button class="show-code">Code</button>
bool         <strong>islandFlag</strong> <a class="anchor-link"
            href="#islandFlag"
            title="Permalink to FrictionJoint.islandFlag">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
islandFlag
</pre>
</div>
</div>
<div class="field inherited"><h4 id="localCenterA">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>localCenterA</strong> <a class="anchor-link"
            href="#localCenterA"
            title="Permalink to FrictionJoint.localCenterA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
localCenterA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="localCenterB">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>localCenterB</strong> <a class="anchor-link"
            href="#localCenterB"
            title="Permalink to FrictionJoint.localCenterB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
localCenterB
</pre>
</div>
</div>
<div class="field"><h4 id="maxForce">
<button class="show-code">Code</button>
num         <strong>maxForce</strong> <a class="anchor-link"
            href="#maxForce"
            title="Permalink to FrictionJoint.maxForce">#</a>
        </h4>
        <div class="doc">
<pre class="source">
num get maxForce =&gt; _maxForce;
</pre>
<pre class="source">
void set maxForce(num force) {
 assert(force &gt;= 0.0);
 _maxForce = force;
}
</pre>
</div>
</div>
<div class="field"><h4 id="maxTorque">
<button class="show-code">Code</button>
num         <strong>maxTorque</strong> <a class="anchor-link"
            href="#maxTorque"
            title="Permalink to FrictionJoint.maxTorque">#</a>
        </h4>
        <div class="doc">
<pre class="source">
num get maxTorque =&gt; _maxTorque;
</pre>
<pre class="source">
void set maxTorque(num torque) {
 assert(torque &gt;= 0.0);
 _maxTorque = torque;
}
</pre>
</div>
</div>
<div class="field inherited"><h4 id="type">
<button class="show-code">Code</button>
int         <strong>type</strong> <a class="anchor-link"
            href="#type"
            title="Permalink to FrictionJoint.type">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
type
</pre>
</div>
</div>
<div class="field inherited"><h4 id="userData">
<button class="show-code">Code</button>
Object         <strong>userData</strong> <a class="anchor-link"
            href="#userData"
            title="Permalink to FrictionJoint.userData">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
userData
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method inherited"><h4 id="destructor">
<button class="show-code">Code</button>
void <strong>destructor</strong>() <a class="anchor-link" href="#destructor"
              title="Permalink to FrictionJoint.destructor">#</a></h4>
<div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<p>Override to handle destruction of joint. </p>
<pre class="source">
void destructor() { }
</pre>
</div>
</div>
<div class="method inherited"><h4 id="getAnchorA">
<button class="show-code">Code</button>
void <strong>getAnchorA</strong>(<a href="../vector_math/vec2.html">vec2</a> argOut) <a class="anchor-link" href="#getAnchorA"
              title="Permalink to FrictionJoint.getAnchorA">#</a></h4>
<div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<p>Get the anchor point on bodyA in world coordinates. </p>
<pre class="source">
void getAnchorA(vec2 argOut) { }
</pre>
</div>
</div>
<div class="method inherited"><h4 id="getAnchorB">
<button class="show-code">Code</button>
void <strong>getAnchorB</strong>(<a href="../vector_math/vec2.html">vec2</a> argOut) <a class="anchor-link" href="#getAnchorB"
              title="Permalink to FrictionJoint.getAnchorB">#</a></h4>
<div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<p>Get the anchor point on bodyB in world coordinates. </p>
<pre class="source">
void getAnchorB(vec2 argOut) { }
</pre>
</div>
</div>
<div class="method"><h4 id="getLocalAnchorA">
<button class="show-code">Code</button>
void <strong>getLocalAnchorA</strong>(<a href="../vector_math/vec2.html">vec2</a> argOut) <a class="anchor-link" href="#getLocalAnchorA"
              title="Permalink to FrictionJoint.getLocalAnchorA">#</a></h4>
<div class="doc">
<pre class="source">
void getLocalAnchorA(vec2 argOut) {
 bodyA.getWorldPointToOut(_localAnchorA, argOut);
}
</pre>
</div>
</div>
<div class="method"><h4 id="getLocalAnchorB">
<button class="show-code">Code</button>
void <strong>getLocalAnchorB</strong>(<a href="../vector_math/vec2.html">vec2</a> argOut) <a class="anchor-link" href="#getLocalAnchorB"
              title="Permalink to FrictionJoint.getLocalAnchorB">#</a></h4>
<div class="doc">
<pre class="source">
void getLocalAnchorB(vec2 argOut) {
 bodyB.getWorldPointToOut(_localAnchorB, argOut);
}
</pre>
</div>
</div>
<div class="method"><h4 id="getReactionForce">
<button class="show-code">Code</button>
void <strong>getReactionForce</strong>(num inv_dt, <a href="../vector_math/vec2.html">vec2</a> argOut) <a class="anchor-link" href="#getReactionForce"
              title="Permalink to FrictionJoint.getReactionForce">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the reaction force on body2 at the joint anchor in Newtons. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
void getReactionForce(num inv_dt, vec2 argOut) {
 argOut.copyFrom(_linearImpulse).scale(inv_dt);
}
</pre>
</div>
</div>
<div class="method"><h4 id="getReactionTorque">
<button class="show-code">Code</button>
num <strong>getReactionTorque</strong>(num inv_dt) <a class="anchor-link" href="#getReactionTorque"
              title="Permalink to FrictionJoint.getReactionTorque">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the reaction torque on body2 in N*m. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
num getReactionTorque(num inv_dt) =&gt; inv_dt * _angularImpulse;
</pre>
</div>
</div>
<div class="method"><h4 id="initVelocityConstraints">
<button class="show-code">Code</button>
void <strong>initVelocityConstraints</strong>(<a href="../box2d/TimeStep.html">TimeStep</a> time_step) <a class="anchor-link" href="#initVelocityConstraints"
              title="Permalink to FrictionJoint.initVelocityConstraints">#</a></h4>
<div class="doc">
<pre class="source">
void initVelocityConstraints(TimeStep time_step) {
 // Compute the effective mass matrix.
 vec2 r1 = _localAnchorA - bodyA.localCenter;
 vec2 r2 = _localAnchorB - bodyB.localCenter;

 bodyA.originTransform.rotation.transform(r1);
 bodyB.originTransform.rotation.transform(r2);

 // J = [-I -r1_skew I r2_skew]
 // [ 0 -1 0 1]
 // r_skew = [-ry; rx]

 // Matlab
 // K = [ mA+r1y^2*iA+mB+r2y^2*iB, -r1y*iA*r1x-r2y*iB*r2x, -r1y*iA-r2y*iB]
 // [ -r1y*iA*r1x-r2y*iB*r2x, mA+r1x^2*iA+mB+r2x^2*iB, r1x*iA+r2x*iB]
 // [ -r1y*iA-r2y*iB, r1x*iA+r2x*iB, iA+iB]

 mat2 K = new mat2.zero();
 K.col0.x = bodyA.invMass + bodyB.invMass +
            bodyA.invInertia * r1.y * r1.y + bodyB.invInertia * r2.y * r2.y;
 K.col0.y = -bodyA.invInertia * r1.x * r1.y - bodyB.invInertia * r2.x * r2.y;
 K.col1.x = K.col0.y;
 K.col1.y = bodyA.invMass + bodyB.invMass +
            bodyA.invInertia * r1.x * r1.x + bodyB.invInertia * r2.x * r2.x;

 mat2 linearMass = new mat2.copy(K);
 linearMass.invert();

 num angularMass = bodyA.invInertia + bodyB.invInertia;
 if (angularMass &gt; 0.0) {
   angularMass = 1.0 / angularMass;
 }

 if (time_step.warmStarting) {
   // Scale impulses.
   _linearImpulse.scale(time_step.dtRatio);
   _angularImpulse *= time_step.dtRatio;

   vec2 P = new vec2.copy(_linearImpulse);

   bodyA.linearVelocity.x -= bodyA.invMass * P.x;
   bodyA.linearVelocity.y -= bodyA.invMass * P.y;
   bodyA.angularVelocity -= bodyA.invInertia * (cross(r1, P) + _angularImpulse);

   bodyB.linearVelocity.x += bodyB.invMass * P.x;
   bodyB.linearVelocity.y += bodyB.invMass * P.y;
   bodyB.angularVelocity += bodyB.invInertia * (cross(r2, P) + _angularImpulse);
 } else {
   _linearImpulse.splat(0.0);
   _angularImpulse = 0.0;
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="solvePositionConstraints">
<button class="show-code">Code</button>
bool <strong>solvePositionConstraints</strong>(num baumgarte) <a class="anchor-link" href="#solvePositionConstraints"
              title="Permalink to FrictionJoint.solvePositionConstraints">#</a></h4>
<div class="doc">
<div class="inherited">
<p>This returns true if the position errors are within tolerance. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
bool solvePositionConstraints(num baumgarte) =&gt; true;
</pre>
</div>
</div>
<div class="method"><h4 id="solveVelocityConstraints">
<button class="show-code">Code</button>
void <strong>solveVelocityConstraints</strong>(<a href="../box2d/TimeStep.html">TimeStep</a> time_step) <a class="anchor-link" href="#solveVelocityConstraints"
              title="Permalink to FrictionJoint.solveVelocityConstraints">#</a></h4>
<div class="doc">
<pre class="source">
void solveVelocityConstraints(TimeStep time_step) {
 // Solve angular friction
 {
   final num Cdot = bodyB.angularVelocity - bodyA.angularVelocity;
   num angularMass = bodyA.invInertia + bodyB.invInertia;
   if (angularMass &gt; 0.0) {
     angularMass = 1.0 / angularMass;
   }
   num impulse = -angularMass * Cdot;

   final num oldImpulse = _angularImpulse;
   final num maxImpulse = time_step.dt * _maxTorque;
   _angularImpulse = clamp(_angularImpulse + impulse, -maxImpulse, maxImpulse);
   impulse = _angularImpulse - oldImpulse;

   bodyA.angularVelocity -= bodyA.invInertia * impulse;
   bodyB.angularVelocity += bodyB.invInertia * impulse;
 }

 // Solve linear friction
 {
   final vec2 r1 = _localAnchorA - bodyA.localCenter;
   final vec2 r2 = _localAnchorB - bodyB.localCenter;

   bodyA.originTransform.rotation.transform(r1);
   bodyB.originTransform.rotation.transform(r2);

   vec2 temp = cross(bodyA.angularVelocity, r1);
   vec2 Cdot = cross(bodyB.angularVelocity, r2);

   Cdot.add(bodyB.linearVelocity).sub(bodyA.linearVelocity).sub(temp);

   mat2 K = new mat2.zero();
   K.col0.x = bodyA.invMass + bodyB.invMass +
              bodyA.invInertia * r1.y * r1.y + bodyB.invInertia * r2.y * r2.y;
   K.col0.y = -bodyA.invInertia * r1.x * r1.y - bodyB.invInertia * r2.x * r2.y;
   K.col1.x = K.col0.y;
   K.col1.y = bodyA.invMass + bodyB.invMass +
              bodyA.invInertia * r1.x * r1.x + bodyB.invInertia * r2.x * r2.x;

   mat2 linearMass = new mat2.copy(K);
   linearMass.invert();

   vec2 impulse = new vec2.copy(Cdot);
   linearMass.transform(impulse);
   impulse.negate();

   vec2 oldImpulse = new vec2.copy(_linearImpulse);
   _linearImpulse.add(impulse);

   num maxImpulse = time_step.dt * _maxForce;
   if (_linearImpulse.length2 &gt; maxImpulse * maxImpulse) {
     _linearImpulse.normalize();
     _linearImpulse.scale(maxImpulse);
   }

   impulse.copyFrom(_linearImpulse).sub(oldImpulse);

   bodyA.linearVelocity.x -= impulse.x * bodyA.invMass;
   bodyA.linearVelocity.y -= impulse.y * bodyA.invMass;
   bodyA.angularVelocity -= bodyA.invInertia * cross(r1, impulse);

   bodyB.linearVelocity.x += impulse.x * bodyB.invMass;
   bodyB.linearVelocity.y += impulse.y * bodyB.invMass;
   bodyB.angularVelocity += bodyB.invInertia * cross(r2, impulse);
 }
}
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
